<?php
	$product_id = $params[1];

	if($_SERVER["REQUEST_METHOD"]=='POST') {
		$title			= strip_tags($_POST['title']);
		$product_code	= strip_tags($_POST['product_code']);
		$url			= stripBlank(strip_tags($_POST['url']));
		$category_id	= $_POST['category_id'];
		$description	= $_POST['description'];
		$keyword		= keyword($description);
		$price			= $_POST['price'];
		$season			= strip_tags($_POST['season']);
		$product_date	= strip_tags($_POST['product_date']);
		$sale			= $_POST['sale'] ? '1': '0';
		$status			= $_POST['status']=='publish' ? '1': '0';
		$ip				= getUserIP();

		$upload_fieldname	= 'thumb';
		$upload_extension	= file_ext($_FILES[$upload_fieldname]['name']);
		$upload_fullpath	= '../contents/product/'.md5('thumb'.time()).$upload_extension;
		if (move_uploaded_file($_FILES[$upload_fieldname]['tmp_name'], $upload_fullpath)) {
			$upload_sql = ", `thumb` = '". basename($upload_fullpath) ."'";
		}

		$upload_fieldname	= 'image';
		$upload_extension	= file_ext($_FILES[$upload_fieldname]['name']);
		$upload_fullpath	= '../contents/product/'.md5('thumb'.time()).$upload_extension;
		if (move_uploaded_file($_FILES[$upload_fieldname]['tmp_name'], $upload_fullpath)) {
			$upload_sql_image = ", `image` = '". basename($upload_fullpath) ."'";
		}

		$sql = "UPDATE `tbl_product` SET `product_code` = '$product_code', `title` = '$title', `description` = '$description', `keyword` = '$keyword', `url` = '$url', `category_id` = '$category_id' , `price` = '$price' $upload_sql $upload_sql_image, `season` = '$season' , `product_date` = '$product_date' ,`ip` = '$ip', `status` = '$status' WHERE `product_id` = $product_id LIMIT 1;";
	 
		mysql_query($sql);
		redirect('../');
		exit;
	}

	$sql = "SELECT * FROM `tbl_product` WHERE `product_id` = '$product_id' LIMIT 1";
	$query = mysql_query($sql);
	while($result = mysql_fetch_assoc($query)) {
		$title			= $result['title'];
		$product_code	= $result['product_code'];
		$url			= $result['url'];
		$category_id	= $result['category_id'];
		$brand_id		= $result['brand_id'];
		$price			= $result['price'];
		$description	= $result['description'];
		$season			= $result['season'];
		$product_date	= $result['product_date'];
		$thumbHTML		= $result['thumb'] ? "<img src=\"/thumb/195/115/zc/contents/product/{$result['thumb']}\" /><br />": "";
		$imageHTML		= $result['image'] ? "<img src=\"/thumb/560/300/zc/contents/product/{$result['image']}\" /><br />": "";
	}
	mysql_free_result($query);
 
	$categoryOption	= _u(arrayOptions($cfg['product']['category'],$category_id),'category');

	include 'ckeditor/ckeditor.php';
	include 'ckeditor/ckfinder/ckfinder.php';
	
	$ckeditor = new CKEditor();
	$ckeditor->returnOutput			= true;
	$ckeditor->basePath				= '/backend/ckeditor/';
	$ckeditor->config['toolbar']	= 'Basic';
	$ckeditor->config['height']		= '100';
	$ckeditor->config['width']		= '600';
	
	CKFinder::SetupCKEditor($ckeditor, '/backend/ckeditor/ckfinder/');
	$descriptionHTML = $ckeditor->editor('description', $description);
?>